/**
 * @description 企业技术服内容
 */
const express = require('express');
const router = express.Router();

const service = require('../api/Service')

/**
 * 用于获取技术服务的接口
 * @route GET /service/list
 * @summary 获取技术服务组列表
 * @group 技术服务
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 * @returns {object} data -请求的数据
 */

router.get('/service/list', async (req, res) => {
    let result = await service.getServiceList();
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "获取数据成功",
            "data": result

        })
    } else {
        res.send("获取数据失败")
    }
})

// swagegr注释
/**
 * @typedef ServiceAdd
 * @property {integer} id
 * @property {string} name.required - Some description for Issue
 * @property {Array.<P1>} P1
 */

/**
 * @typedef P1
 * @property {string} name.required  -新建任务组名称
 * @property {string} img.required -新新建任务图片链接
 */

/**
 * 用于创建技术服务的接口
 * @route POST /service/list/add
 * @summary 创建新的技术服务组
 * @group 技术服务
 * @param {P1.model} point.body.required
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */
router.post('/service/list/add', async (req, res) => {
    let name = req.body.name;
    let img = req.body.img;
    let result = await service.createServiceGroup(name, img);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "创建成功"
        })
    } else {
        res.send("创建失败")
    }
})


// swagegr注释
/**
 * @typedef ServiceUpdate
 * @property {integer} id
 * @property {string} name.required - Some description for Issue
 * @property {Array.<P2>} P2
 */

/**
 * @typedef P2
 * @property {integer} id.required  -修改技术服组索引id
 * @property {string} name.required  -新建任务组名称
 * @property {string} img.required -新新建任务图片链接
 */

/**
 * 用于修改技术服务的接口
 * @route POST /service/list/update
 * @summary 创建新的技术服务组
 * @group 技术服务
 * @param {P2.model} point.body.required -
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/update', async (req, res) => {
    let id = req.body.id;
    let name = req.body.name;
    let img = req.body.img;
    let result = await service.updateServieGroup(name, img, id);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "修改成功"
        })
    } else {
        res.send("修改失败")
    }
})


// swagegr注释
/**
 * @typedef ServiceSublistAdd
 * @property {integer} id
 * @property {string} name.required - Some description for Issue
 * @property {Array.<P3>} P3
 */

/**
 * @typedef P3
 * @property {integer} parentId.required  -技术服务组索引id
 * @property {string} name.required -创建子服务名称名称
 */

/**
 * 用于创建技术服务子服务的接口
 * @route POST /service/list/sublist/add
 * @summary 创建新的技术服务组下的子服务
 * @group 技术服务
 * @param {P3.model} point.body.required 
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/add', async (req, res) => {
    let parentId = await req.body.parentId;
    let name = await req.body.name;
    let result = await service.createSubService(parentId, name);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "创建成功"
        })
    } else {
        res.send("创建失败")
    }
})



// swagegr注释
/**
 * @typedef ServiceSublistDelete
 * @property {integer} id
 * @property {string} name.required - Some description for Issue
 * @property {Array.<P4>} P4
 */

/**
 * @typedef P4
 * @property {integer} parentId.required  -技术服务组索引id
 * @property {string} id.required -要删除的子服务名称
 */

/**
 * 用于删除技术服务子服务的接口
 * @route POST /service/list/sublist/delete
 * @summary 删除技术服务组下的子服务
 * @param {P4.model} point.body.required
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/delete', async (req, res) => {
    let parentId = await req.body.parentId;
    let id = await req.body.parentId;
    let result = await service.createSubService(parentId, id);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "删除成功"
        })
    } else {
        res.send("删除失败")
    }
})


// swagegr注释
/**
 * @typedef ServiceSublistUpdate
 * @property {integer} id
 * @property {string} name.required - Some description for Issue
 * @property {Array.<P5>} P5
 */

/**
 * @typedef P5
 * @property {integer} parentId.required  -技术服务组索引id
 * @property {integer} parentId.required  -子服务索引id
 * @property {string} name.required -修改后子服务名称名称
 */

/**
 * 用于修改技术服务子服务的接口
 * @route POST /service/list/sublist/update
 * @summary 修改技术服务组下的子服务名称
 * @group 技术服务
 * @param {P5.model} point.body.required 
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/update', async (req, res) => {
    let parentId = await req.body.parentId;
    let id = await req.body.id;
    let name = await req.body.name;
    let result = await service.updateSubService(parentId, id, name);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "创建成功"
        })
    } else {
        res.send("创建失败")
    }
})


/**
 * 用于获取子服务展示页的接口
 * @route GET /service/list/sublist/show
 * @summary 获取子服展示信息
 * @group 技术服务
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 * @returns {object} data -请求返回数据
 */

router.get('/service/list/sublist/show', async (req, res) => {
    let result = await service.getShowSubService()
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "获取成功",
            "data": result
        })
    } else {
        res.send("获取失败")
    }
})


/**
 * 用于创建子服务展示页案例的接口
 * @route POST /service/list/sublist/show/add
 * @summary 创建子服务展示页案例
 * @group 技术服务
 * @param {number} parentId.body.required -子服务索引id
 * @param {number} img.body.required -展示案例图片链接地址
 * @param {string} ppt.body.required -展示案例ppt链接地址
 * @param {string} mv.body.required -展示案例视频链接地址
 * @param {string} online.body.required -展示案例在线演示地址
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/show/add', async (req, res) => {
    let parentId = await req.body.parentId;
    let img = await req.body.img;
    let ppt = await req.body.name;
    let mv = await req.body.mv;
    let online = await req.body.online;
    let result = await service.createShowSubService(parentId, img, ppt, mv, online);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "创建成功"
        })
    } else {
        res.send("创建失败")
    }
})


/**
 * 用于修改子服务项案例内容的接口
 * @route POST /service/list/sublist/show/update
 * @summary 修改子服务项案例内容
 * @group 技术服务
 * @param {number} parentId.body.required -子服务索引
 * @param {number} id.body.required -子服务展示案例索引
 * @param {number} img.body.required -展示案例图片链接地址
 * @param {string} ppt.body.required -展示案例ppt链接地址
 * @param {string} mv.body.required -展示案例视频链接地址
 * @param {string} online.body.required -展示案例在线演示地址
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/show/update', async (req, res) => {
    let parentId = await req.body.parentId;
    let id = await req.body.id;
    let img = await req.body.img;
    let ppt = await req.body.name;
    let mv = await req.body.mv;
    let online = await req.body.online;
    let result = await service.updateShowSubService(parentId, id, img, ppt, mv, online);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "修改成功"
        })
    } else {
        res.send("修改失败")
    }
})


/**
 * 用于删除子服务项案例内容的接口
 * @route POST /service/list/sublist/show/delete
 * @summary 删除子服务项案例内容
 * @group 技术服务
 * @param {number} parentId.body.required -子服务索引
 * @param {number} id.body.required -子服务展示案例索引
 * @param {number} img.body.required -展示案例图片链接地址
 * @param {string} ppt.body.required -展示案例ppt链接地址
 * @param {string} mv.body.required -展示案例视频链接地址
 * @param {string} online.body.required -展示案例在线演示地址
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/show/delete', async (req, res) => {
    let parentId = await req.body.parentId;
    let id = await req.body.id;
    let result = await service.deleteShowSubService(parentId, id);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "删除成功"
        })
    } else {
        res.send("删除失败")
    }
})


/**
 * 用于获取子服务项案例详情信息的接口
 * @route POST /service/list/show/example/info
 * @summary 获取子服务项案例详情
 * @group 技术服务
 * @param {number} parentId.body.required -子服务索引
 * @param {number} id.body.required -子服务展示案例索引
 * @param {number} img.body.required -展示案例图片链接地址
 * @param {string} ppt.body.required -展示案例ppt链接地址
 * @param {string} mv.body.required -展示案例视频链接地址
 * @param {string} online.body.required -展示案例在线演示地址
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.get('/service/list/show/example/info', async (req, res) => {
    let result = await service.getExampleInfo();
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "获取数据成功",
            "data": result

        })
    } else {
        res.send("获取数据失败")
    }
})


 /**
 * 用于创建子服务项案例详情信息的接口
 * @route POST /service/list/sublist/show/example/info/add
 * @summary 创建子服务项案例详情
 * @group 技术服务
 * @param {number} parentId.body.required -子服务索引
 * @param {number} id.body.required -子服务展示案例索引
 * @param {number} img.body.required -展示案例图片链接地址
 * @param {string} ppt.body.required -展示案例ppt链接地址
 * @param {string} mv.body.required -展示案例视频链接地址
 * @param {string} online.body.required -展示案例在线演示地址
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/show/example/info/add', async (req, res) => {
    let parentId = await req.body.parentId;
    let img = await req.body.img;
    let description_list = await req.body.name;
    let result = await service.createShowSubService(parentId, img, description_list);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "创建成功"
        })
    } else {
        res.send("创建失败")
    }
})


  /**
 * 用于修改子服务项案例详情信息的接口
 * @route  /service/list/sublist/show/example/info/update
 * @summary 修改子服务项案例详情
 * @group 技术服务
 * @param {number} parentId.body.required -子服务索引
 * @param {number} id.body.required -子服务展示案例索引
 * @param {number} img.body.required -展示案例图片链接地址
 * @param {string} ppt.body.required -展示案例ppt链接地址
 * @param {string} mv.body.required -展示案例视频链接地址
 * @param {string} online.body.required -展示案例在线演示地址
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/show/example/info/update', async (req, res) => {
    let parentId = await req.body.parentId;
    let id = await req.body.id;
    let img = await req.body.img;
    let description_list = await req.body.description_list;
    let result = await service.updateShowSubService(parentId, id, img, description_list);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "修改成功"
        })
    } else {
        res.send("修改失败")
    }
})


/**
 * 用于删除子服务项案例详情信息的接口
 * @route POST /service/list/sublist/show/example/info/update
 * @summary 删除子服务项案例详情
 * @group 技术服务
 * @param {number} parentId.body.required -子服务索引
 * @param {number} id.body.required -子服务展示案例索引
 * @param {number} img.body.required -展示案例图片链接地址
 * @param {string} ppt.body.required -展示案例ppt链接地址
 * @param {string} mv.body.required -展示案例视频链接地址
 * @param {string} online.body.required -展示案例在线演示地址
 * @returns {object} SUCCESS -返回成功状态
 * @returns {object} msg -请求成功提示
 */

router.post('/service/list/sublist/show/example/info/update', async (req, res) => {
    let parentId = await req.body.parentId;
    let id = await req.body.id;
    let result = await service.deleteExampleInfo(parentId, id);
    if (result) {
        res.send({
            "code": "SUCCESS",
            "msg": "删除成功"
        })
    } else {
        res.send("删除失败")
    }
})


module.exports = router;